#include <stdio.h>
#include <stdlib.h>
#include<sys/wait.h>
#include <unistd.h>
int main() {
	pid_t id = fork();
	if (id == -1) {
		perror("fork error");
	}
	else if (id == 0) {
		//child
		int count = 0;
		while (count < 3) {
			printf("child[%d] is running...\n", getpid());
			sleep(1);
			count++;
		}
		exit(88);
	}
	//father
	printf("fater wait before\n");
	int st = 0;
	pid_t ret = waitpid(id, &st, 0);
	if (ret > 0) {
		printf("wait success\n");
		printf("st: %d \n", st);
        //获取status中高八位的方式获取status中的子进程退出信息
		printf("child exit code: %d\n", (st >> 8));
        //获取status中低七位的方式获取子进程的退出信号
		printf("signal code: %d\n", st & 0x7f);
	}
	else {
		printf("wait filed\n");
	}
	printf("father wait after\n");
	return 0;
}
